package com.yanqu.road.logic.activity.foxcard.game.spell;

import com.yanqu.road.entity.activity.foxcard.FoxBaseCard;
import com.yanqu.road.entity.activity.foxcard.FoxHandCard;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardShowInfo;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardShowType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 选手牌使其加点数
 * 数量|增加的点数
 */
public class FoxCardSpellUse7 extends FoxCardSpellUseBase {
    @Override
    protected boolean spellUse(FoxCardGameLogic gameLogic) {
        int num = spellConfig.getParamList().get(0);
        int targetNum = targetIdList.size();
        if (targetNum <= 0 || targetNum > num) {
            return false;
        }

        int pointAdd = spellConfig.getParamList().get(1);

        int minPoint = 1;
        int maxPoint = gameLogic.getConfig().getPointToScoreMap().size();

        for (Integer handCardId : targetIdList) {
            FoxHandCard foxHandCard = gameLogic.getGameData().getHandCards().stream().filter(handCard -> handCard.getId() == handCardId).findFirst().orElse(null);
            if (foxHandCard == null) {
                return false;
            }
//            if (gameLogic.getConfig().isNotPointAndNotColorHandCard(foxHandCard.getReinforceEffect())) {
//                return false;
//            }
            int pointChange = foxHandCard.getPoint() + pointAdd;
            //point的范围是1-13
            int point = pointChange % maxPoint;
            if (point == 0) {
                point = maxPoint;
            }
            foxHandCard.setPoint(point);

            FoxCardShowInfo showInfo = gameLogic.newFoxShow(eFoxCardShowType.POINT_CHANGE.getValue());
            showInfo.setTriggerCards(Collections.singletonList(foxHandCard));
            showInfo.setShowValue(point);
        }

        return true;
    }
}
